/*
 * Copyright (c) 2017. 深圳一七科技. All rights reserved.
 */

package com.yiqi.liebang.feature.mine.presenter;

import android.text.TextUtils;

import com.yiqi.liebang.entity.bo.AddTopicBo;
import com.yiqi.liebang.entity.bo.UserCardBo;
import com.yiqi.liebang.entity.bo.UserParamBo;
import com.yiqi.liebang.feature.mine.contract.CertificationContract;
import com.yiqi.liebang.feature.mine.contract.TopicContract;
import com.yiqi.liebang.feature.mine.dependencies.certification.DaggerCertificationPresenterComponent;
import com.yiqi.liebang.feature.mine.dependencies.topic.DaggerTopicPresenterComponent;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2018/7/11 9:31
 */
public class TopicPresenter implements TopicContract.Presenter {

    private TopicContract.View mView;

    @Inject

    TopicContract.Model mModel;


    public TopicPresenter(TopicContract.View mView) {
        this.mView = mView;
        DaggerTopicPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void userAddTopic(String topicName, String serviceType, String serviceTime,
                             double topicPrice, double originalPrice, String serviceIn, String Remarks) {
        if (TextUtils.isEmpty(topicName)) {
            mView.showError("请输入话题名称！");
            return;
        }
        if (TextUtils.isEmpty(serviceTime)) {
            mView.showError("请选择话题时常！");
            return;
        }
        if (TextUtils.isEmpty(serviceIn)) {
            mView.showError("请输入服务介绍！");
            return;
        }

        if (topicPrice <= 0) {
            mView.showError("请输入有效的话题价格！");
            return;
        }
        if (originalPrice <= 0) {
            mView.showError("请输入有效的话题价格！");
            return;
        }
        AddTopicBo addTopicBo = new AddTopicBo(topicName, serviceType, serviceTime, topicPrice, originalPrice, serviceIn, Remarks);
        mModel.userAddTopic(addTopicBo).compose(mView.bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(String s) {
                mView.showAddTopicSuccess();
                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
                mView.showError(e.getMessage());
                mView.dismissLoading();
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void userEditTopic(String id, String topicName, String serviceType, String serviceTime, double topicPrice, double originalPrice, String serviceIn, String Remarks) {
        if (TextUtils.isEmpty(topicName)) {
            mView.showError("请输入话题名称！");
            return;
        }
        if (TextUtils.isEmpty(serviceTime)) {
            mView.showError("请选择话题时常！");
            return;
        }
        if (TextUtils.isEmpty(serviceIn)) {
            mView.showError("请输入服务介绍！");
            return;
        }

        if (topicPrice <= 0) {
            mView.showError("请输入有效的话题价格！");
            return;
        }
        if (originalPrice <= 0) {
            mView.showError("请输入有效的话题价格！");
            return;
        }
        AddTopicBo addTopicBo = new AddTopicBo(id,topicName, serviceType, serviceTime, topicPrice, originalPrice, serviceIn, Remarks);


        mModel.userEditTopic(addTopicBo).compose(mView.bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(String s) {
                mView.showAddTopicSuccess();
                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
                mView.showError(e.getMessage());
                mView.dismissLoading();
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }
}
